/* 
 * 常用工具函数
 */

/**
 *根据输入日期与当前日期比较,得到相差的时间,显示给用户
 *param date - 要比较的时间，字符串，格式："2013-06-22 23:34:00"
 **/
function getDateString(date)
{
	var d1=date.split(" ")[0];
	var t1=date.split(" ")[1];
	
	var y1=d1.split("-")[0];
	var m1=d1.split("-")[1];
	var da1=d1.split("-")[2];
	
	var h1=t1.split(":")[0];
	var mi1=t1.split(":")[1];
	var s1=t1.split(":")[2];
	
	var dat_t = new Date(y1,parseInt(m1)-1,da1,h1,mi1,s1);
	var y_t = dat_t.getFullYear();
	var m_t = dat_t.getMonth() + 1;
	var d_t = dat_t.getDate();
	var h_t = dat_t.getHours();
	var mi_t = dat_t.getMinutes();
	
	var dat_now = new Date();
	var y_now = dat_now.getFullYear();
	var m_now = dat_now.getMonth() + 1;
	var d_now = dat_now.getDate();
	var h_now = dat_now.getHours();
	var mi_now = dat_now.getMinutes();
	
	//alert(y_t + " " + m_t + " " + d_t + " " + h_t + " " + mi_t + " " + s_t);
	//alert(y_now + " " + m_now + " " + d_now + " " + h_now + " " + mi_now + " " + s_now);
	
	var ret = y1 + "年" + m1 + "月" + da1 + "日 " + h1 + ":" + mi1 + ":" + s1;
	var diff = 0;
	if(dat_t > dat_now)
	{
		//直接返回默认字符串
	}
	else if(y_t < y_now)
	{
		//返回年月日
		ret = y1 + "年" + m1 + "月" + da1 + "日";
	}
	else if(m_t < m_now)
	{
		//返回月日
		ret = m1 + "月" + da1 + "日";
	}
	else if(d_t < d_now)
	{
		//X天前
		diff = d_now - d_t;
		if(diff == 1)
		{
			ret = "昨天";
		}
		else
		{
			ret = diff + "天前";
		}
	}
	else if(h_t < h_now)
	{
		//X小时前
		diff = h_now - h_t;
		ret = diff + "小时前";
	}
	else if(mi_t < mi_now)
	{
		//X分钟前
		diff = mi_now - mi_t;
		ret = diff + "分钟前";
	}
	else
	{
		ret = "刚刚";
	}
	
	return ret;
}

